﻿//快速登录
function quickLogin(){
	var identify = jQuery("#identify").val();
	var password = jQuery("#password").val();
	var authtype = '1';
	var validateCode = jQuery("#validateCode").val();
	var returnURl = window.location.href;
	var rd = document.getElementsByName("authtype");
	for(i=0;i <rd.length;i++)  
	{  
	 if(rd[i].checked==true)
		 authtype=rd[i].value;
	}
	jQuery.post('/ajax_quickLogin.do', 
	{identify: identify,
	 password:password,
	 authtype:authtype,
	 validateCode:validateCode,
	 returnURl:returnURl},  
	function (data){ //回传函数 
		 jQuery("#error_code").html(data);
	});
}

//下一张验证码
function changeImg(){   
    var imgSrc = jQuery("#imgObj");   
    var src = imgSrc.attr("src");   
    imgSrc.attr("src",chgurl(src));   
}   
//时间戳   
//为了使每次生成图片不一致，即不让浏览器读缓存，所以需要加上时间戳   
function chgurl(url){   
    var timestamp = (new Date()).valueOf();    
    if((url.indexOf("&")>=0)){   
        url = url + "×tamp=" + timestamp;   
    }else{   
        url = url + "?timestamp=" + timestamp;   
    }   
    return url;   
}


//等级
<!-- 很差，较差，还不错，比较好，太棒了 -->

function grade(i,grade_,div,gradeNum,onclick){
		
	var grade_1=document.getElementById(grade_+'1');
	var grade_2=document.getElementById(grade_+'2');
	var grade_3=document.getElementById(grade_+'3');
	var grade_4=document.getElementById(grade_+'4');
	var grade_5=document.getElementById(grade_+'5');

	var div_1=document.getElementById(div);
	var grade_check=document.getElementById(gradeNum).value;
	div_1.style.display="block";
	if(i==1){
	grade_1.src=staticURL+"/images/bspace/icon_star_2.gif";
	grade_2.src=staticURL+"/images/bspace/icon_star_1.gif";
	grade_3.src=staticURL+"/images/bspace/icon_star_1.gif";
	grade_4.src=staticURL+"/images/bspace/icon_star_1.gif";
	grade_5.src=staticURL+"/images/bspace/icon_star_1.gif";
	div_1.innerHTML="1星差";
	if(onclick=='Y')document.getElementById(gradeNum).value=1;
	}
	if(i==2){
	grade_1.src=staticURL+"/images/bspace/icon_star_2.gif";
	grade_2.src=staticURL+"/images/bspace/icon_star_2.gif";
	grade_3.src=staticURL+"/images/bspace/icon_star_1.gif";
	grade_4.src=staticURL+"/images/bspace/icon_star_1.gif";
	grade_5.src=staticURL+"/images/bspace/icon_star_1.gif";
	div_1.innerHTML="2星一般";
	if(onclick=='Y')document.getElementById(gradeNum).value=2;
	}
	if(i==3){
	grade_2.src=staticURL+"/images/bspace/icon_star_2.gif";
	grade_1.src=staticURL+"/images/bspace/icon_star_2.gif";
	grade_3.src=staticURL+"/images/bspace/icon_star_2.gif";
	grade_4.src=staticURL+"/images/bspace/icon_star_1.gif";
	grade_5.src=staticURL+"/images/bspace/icon_star_1.gif";
	div_1.innerHTML="3星好";
	if(onclick=='Y')document.getElementById(gradeNum).value=3;
	}
	if(i==4){
	grade_2.src=staticURL+"/images/bspace/icon_star_2.gif";
	grade_1.src=staticURL+"/images/bspace/icon_star_2.gif";
	grade_3.src=staticURL+"/images/bspace/icon_star_2.gif";
	grade_4.src=staticURL+"/images/bspace/icon_star_2.gif";
	grade_5.src=staticURL+"/images/bspace/icon_star_1.gif";
	div_1.innerHTML="4星很好";
	if(onclick=='Y')document.getElementById(gradeNum).value=4;
	}
	if(i==5){
	grade_2.src=staticURL+"/images/bspace/icon_star_2.gif";
	grade_1.src=staticURL+"/images/bspace/icon_star_2.gif";
	grade_3.src=staticURL+"/images/bspace/icon_star_2.gif";
	grade_4.src=staticURL+"/images/bspace/icon_star_2.gif";
	grade_5.src=staticURL+"/images/bspace/icon_star_2.gif";
	div_1.innerHTML="5星非常好";
	if(onclick=='Y')document.getElementById(gradeNum).value=5;
	}
}
	
	function grade_over(grade_,div,gradeNum){
		
	var grade_1=document.getElementById(grade_+'1');
	var grade_2=document.getElementById(grade_+'2');
	var grade_3=document.getElementById(grade_+'3');
	var grade_4=document.getElementById(grade_+'4');
	var grade_5=document.getElementById(grade_+'5');

	var div_1=document.getElementById(div);
	var grade_check=document.getElementById(gradeNum).value;
	div_1.style.display="none";
	if(grade_check==0){
	grade_1.src=staticURL+"/images/bspace/icon_star_1.gif";
	grade_2.src=staticURL+"/images/bspace/icon_star_1.gif";
	grade_3.src=staticURL+"/images/bspace/icon_star_1.gif";
	grade_4.src=staticURL+"/images/bspace/icon_star_1.gif";
	grade_5.src=staticURL+"/images/bspace/icon_star_1.gif";
	}
	if(grade_check==1){
	grade_1.src=staticURL+"/images/bspace/icon_star_2.gif";
	grade_2.src=staticURL+"/images/bspace/icon_star_1.gif";
	grade_3.src=staticURL+"/images/bspace/icon_star_1.gif";
	grade_4.src=staticURL+"/images/bspace/icon_star_1.gif";
	grade_5.src=staticURL+"/images/bspace/icon_star_1.gif";
	}
	if(grade_check==2){
	grade_1.src=staticURL+"/images/bspace/icon_star_2.gif";
	grade_2.src=staticURL+"/images/bspace/icon_star_2.gif";
	grade_3.src=staticURL+"/images/bspace/icon_star_1.gif";
	grade_4.src=staticURL+"/images/bspace/icon_star_1.gif";
	grade_5.src=staticURL+"/images/bspace/icon_star_1.gif";
	}
	if(grade_check==3){
	grade_2.src=staticURL+"/images/bspace/icon_star_2.gif";
	grade_1.src=staticURL+"/images/bspace/icon_star_2.gif";
	grade_3.src=staticURL+"/images/bspace/icon_star_2.gif";
	grade_4.src=staticURL+"/images/bspace/icon_star_1.gif";
	grade_5.src=staticURL+"/images/bspace/icon_star_1.gif";
	}
	if(grade_check==4){
	grade_2.src=staticURL+"/images/bspace/icon_star_2.gif";
	grade_1.src=staticURL+"/images/bspace/icon_star_2.gif";
	grade_3.src=staticURL+"/images/bspace/icon_star_2.gif";
	grade_4.src=staticURL+"/images/bspace/icon_star_2.gif";
	grade_5.src=staticURL+"/images/bspace/icon_star_1.gif";
	}
	if(grade_check==5){
	grade_2.src=staticURL+"/images/bspace/icon_star_2.gif";
	grade_1.src=staticURL+"/images/bspace/icon_star_2.gif";
	grade_3.src=staticURL+"/images/bspace/icon_star_2.gif";
	grade_4.src=staticURL+"/images/bspace/icon_star_2.gif";
	grade_5.src=staticURL+"/images/bspace/icon_star_2.gif";
	}
}

function grade_clear(num,max){
	for(i = num; i<max; i++){
		document.getElementById('grade'+i+'_1').src=staticURL+"/images/bspace/icon_star_1.gif";
		document.getElementById('grade'+i+'_2').src=staticURL+"/images/bspace/icon_star_1.gif";
		document.getElementById('grade'+i+'_3').src=staticURL+"/images/bspace/icon_star_1.gif";
		document.getElementById('grade'+i+'_4').src=staticURL+"/images/bspace/icon_star_1.gif";
		document.getElementById('grade'+i+'_5').src=staticURL+"/images/bspace/icon_star_1.gif";
	}
}

//显示店铺标签
function showTag(tag) {
	var tagContent = jQuery("#tag").val();
	jQuery("#tag").val(tagContent + tag + ",");
}

//显示用餐目的标签
function showHaveDinner(haveDinner) {
	var tagContent = jQuery("#haveDinner").val();
	jQuery("#haveDinner").val(tagContent + haveDinner + ",");
}

//显示打折卡标签
function showDiscount(discount) {
	var tagContent = jQuery("#discount").val();
	jQuery("#discount").val(tagContent + discount + ",");
}

//点评内容的字数计数
function CountWords(){
	var countAll=5000;
	var countUsed=0;
	var content=jQuery("#commentDetail").val();
	if(countAll<Length(content)){
		alert("点评内容的长度超过了"+countAll+"的字数限制!\n超过的部分将被截取!");
		content=SubString(content,countAll);
		jQuery("#commentDetail").val(content);
	}
	countUsed=Length(content);
	var countRemain=countAll-countUsed;
	jQuery("#contentCount").html('<tb class="asred" id="contentCount">'+countUsed+'/'+countAll+'</tb>');
}	
//截取指定长度字符串
function content(index){
	var countAll=5000;
	var content=jQuery("#content"+index).val();
	if(countAll<Length(content)){
	    content=SubString(content,countAll);
	    jQuery("#content"+index).val()=content;
	}
}

//判断是否匿名：登录
function checkAnoymous(){
	if(!document.getElementById("anonymous").checked){
		isPersonLogin();
	}
}

//检查提交内容是否包含非法关键字	
function checkInput(content){
jQuery.post('/checkKeyWord.do', 
{keyWord: content},  
function (data){ //回传函数 
	if(parseInt(data)){
	  alert('对不起你输入的文字包含不允许的字符，请注意');
	  return false;
	}
}); 
}

//检验消费类点评评分
function ckeckConsume(){
	var gradeNum2 = jQuery("#gradeNum2").val();
	var gradeNum3 = jQuery("#gradeNum3").val();
	var gradeNum4 = jQuery("#gradeNum4").val();
	if(gradeNum2=="0" || gradeNum2=="undefined"){
		alert("请给该商家的服务评分!");
	     return false;	
	}
	if(gradeNum3=="0" || gradeNum3=="undefined"){
		alert("请给该商家的环境评分!");
	     return false;	
	}
	if(gradeNum4=="0" || gradeNum4=="undefined"){
		alert("请给该商家的性价比评分!");
	     return false;	
	}
}
//检验非消费类点评评分
function ckeckNotConsume(){
	var gradeNum1 = jQuery("#gradeNum1").val();
	if(gradeNum1=="0" || gradeNum1=="undefined"){
		alert("请给该商家的综合评分!");
	     return false;	
	}
}

//添加非餐饮点评
function addComment(){
	var companyId = jQuery("#companyId").val();
	var companyName = jQuery("#companyName").val();
	var objectURL = jQuery("#objectURL").val();
	var personRegionName = jQuery("#personRegionName").val();
	var commentDetail = jQuery("#commentDetail").val();
	var gradeNum1 = jQuery("#gradeNum1").val();
	var gradeNum2 = "0";
	var gradeNum3 = "0";
	var gradeNum4 = "0";
	var tag = jQuery("#tag").val();
	var objectType = jQuery("#objectType").val();
	var companyType = jQuery("#companyType").val();
	var average = jQuery("#average").val();
	
	//对不同类型的点评进行验证
	if(objectType==8){
		ckeckConsume();
		var gradeNum2 = jQuery("#gradeNum2").val();
		var gradeNum3 = jQuery("#gradeNum3").val();
		var gradeNum4 = jQuery("#gradeNum4").val();
	}else{
		ckeckNotConsume();
	}
	
	if(document.getElementById("anonymous").checked){
		var anonymous = 'true';
	}else{
		var anonymous = 'false';
	}
	
	if(isNull(commentDetail)){
	   alert("请输入评论内容!");
	   jQuery("#commentDetail").focus();
	   return false;
	}
	
	if(Length(commentDetail)<20){
	   alert("点评内容不能少于20个字!");
	   jQuery("#commentDetail").focus();
	   return false;
	}
	
	if(average){
		if(Length(average) > 6){
			alert("请不要恶意点评人均消费,人均消费在0-999999之间!");
			return false;
		}
	}

	
	checkInput(commentDetail);
	
   jQuery.post('/comment_add.do', 
    {content:commentDetail,
    	synthesized:gradeNum1,
    	service:gradeNum2,
    	environment:gradeNum3,
    	costCompare:gradeNum4,
    	anonymous:anonymous,
    	average:average,
        tag:tag,
    	personRegionName:personRegionName,
    	objectUrl:objectURL,
    	objectId:companyId,
    	objectName:companyName,
    	objectType:objectType},  
	    function (data){ //回传函数 
    		alert(data);
		}); 
   //提交后清空添加点评的信息
//   jQuery("#contentCount").html('<tb class="asred" id="contentCount">0/500</tb>');
//   if(objectType==8){
//	   grade_clear(2,5);
//   }else{
//	   grade_clear(1,2);
//   }
   
//   var windowURL=location.href; 
//   if(windowURL.indexOf('index')>0){
//	   if(companyType.indexOf('j')<0){
//		   jQuery("#indexcommentnew").html('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="/images/loading.gif" align="middle"/>');
//		   jQuery.post('/comment_list.do', 
//			{companyId: companyId,ajaxComment:'ajaxComment',pageNum:1,pageCount:6}, 
//			function (data){ //回传函数 
//				jQuery("div#indexcommentnew").html(data);
//			});
//	   }else{
//		   jQuery("#jdianping").html('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="/images/loading.gif" align="middle"/>');
//		   jQuery.post('/comment_list.do', 
//			{companyId: companyId,ajaxComment:'ajaxCommentPage',pageNum:1,pageCount:6}, 
//			function (data){ //回传函数 
//				jQuery("div#jdianping").html(data);
//			}); 
//	   }
//   }else{
	   window.location.reload();
//   }
//   
//   document.addCommentForm.reset();
}

//添加餐饮点评
function addFComment(){
	var companyId = jQuery("#companyId").val();
	var companyName = jQuery("#companyName").val();
	var objectURL = jQuery("#objectURL").val();
	var personRegionName = jQuery("#personRegionName").val();
	var commentDetail = jQuery("#commentDetail").val();
	var gradeNum2 = jQuery("#gradeNum2").val();
	var gradeNum3 = jQuery("#gradeNum3").val();
	var gradeNum4 = jQuery("#gradeNum4").val();
	var haveDinner = jQuery("#haveDinner").val();
	var recommendFoo = jQuery("#recommendFoo").val();
	var discount = jQuery("#discount").val();
	var average = jQuery("#average").val();
	var companyType = jQuery("#companyType").val();
	
	if(commentDetail.indexOf('\n')>0){
		commentDetail=commentDetail.replace('<br/>','\n'); 
	}

	//匿名赋值
	if(document.getElementById("anonymous").checked){
		var anonymous = 'true';
	}else{
		var anonymous = 'false';
	}
	if(gradeNum2=="0" || gradeNum2=="undefined"){
		alert("请给该商家的环境评分!");
	     return false;	
	} 
	if(gradeNum3=="0" || gradeNum3=="undefined"){
		alert("请给该商家的服务评分!");
	     return false;	
	}
	if(gradeNum4=="0" || gradeNum4=="undefined"){
		alert("请给该商家的口味评分!");
	     return false;	
	}
	if(isNull(commentDetail)){
	   alert("请输入评论内容!");
	   jQuery("#commentDetail").focus();
	   return false;
	}
	if(isNull(average)){
		alert("请填写人均消费!");
		jQuery("#average").focus();
	    return false;	
	}
	if(!isValidNum(average)){
		alert("请填写正确的人均消费!");
		jQuery("#average").focus();
	    return false;
	}
	if(Length(average) > 6){
		alert("请不要恶意点评人均消费,人均消费在0-999999之间!");
		return false;
	}
	if(isNull(haveDinner)){
		 alert("请输入用餐目的!");
		 jQuery("#haveDinner").focus();
		 return false;
	}
	if(Length(commentDetail)<20){
	   alert("点评内容不能少于20个字!");
	   jQuery("#commentDetail").focus();
	   return false;
	}
	
	checkInput(commentDetail);
	commentDetail = commentDetail.replaceAll('\n','<br/>');
   jQuery.post('/comment_add.do', 
    {content:commentDetail,
    	service:gradeNum2,
    	environment:gradeNum3,
    	taste:gradeNum4,
    	objectType:7,
    	haveDinner:haveDinner,
   		recommendFoo:recommendFoo,
   		discount:discount,
    	anonymous:anonymous,
    	average:average,
    	personRegionName:personRegionName,
    	objectUrl:objectURL,
    	objectId:companyId,
    	objectName:companyName},  
	    function (data){ //回传函数 
		 alert(data);
		}); 
   //提交后清空添加点评的信息
//   jQuery("#contentCount").html('<tb class="asred" id="contentCount">0/500</tb>');
//   grade_clear(2,5);
//   
//   var windowURL=location.href; 
//   if(windowURL.indexOf('index')>0){
//	   if(companyType.indexOf('j')<0){
//		   jQuery("#indexcommentnew").html('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="/images/loading.gif" align="middle"/>');
//		   getCommentNew();//动态加载商家点评列表
//	   }else{
//		   jQuery("#jdianping").html('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="/images/loading.gif" align="middle"/>');
//		   getCommentPage(1);
//	   }
//   }else{
	   window.location.reload();
//   }
//   
//   document.addFCommentForm.reset();
}

//添加订餐餐饮点评
function addFoodV2Comment(){
	var companyId = jQuery("#companyId").val();
	var companyName = jQuery("#companyName").val();
	var objectURL = jQuery("#objectURL").val();
	var personRegionName = jQuery("#personRegionName").val();
	var commentDetail = jQuery("#commentDetail").val();
	var gradeNum2 = jQuery("#gradeNum2").val();
	var gradeNum3 = jQuery("#gradeNum3").val();
	var gradeNum4 = jQuery("#gradeNum4").val();
	var haveDinner = jQuery("#haveDinner").val();
	var recommendFoo = jQuery("#recommendFoo").val();
	var discount = jQuery("#discount").val();
	var average = jQuery("#average").val();
	var token = jQuery("#token").val();
	var companyType = jQuery("#companyType").val();
	
	if(commentDetail.indexOf('\n')>0){
		commentDetail=commentDetail.replace('<br/>','\n'); 
	}

	//匿名赋值
	if(document.getElementById("anonymous").checked){
		var anonymous = 'true';
	}else{
		var anonymous = 'false';
	}
	if(gradeNum2=="0" || gradeNum2=="undefined"){
		alert("请给该商家的环境评分!");
	     return false;	
	} 
	if(gradeNum3=="0" || gradeNum3=="undefined"){
		alert("请给该商家的服务评分!");
	     return false;	
	}
	if(gradeNum4=="0" || gradeNum4=="undefined"){
		alert("请给该商家的口味评分!");
	     return false;	
	}
	if(isNull(commentDetail)){
	   alert("请输入评论内容!");
	   jQuery("#commentDetail").focus();
	   return false;
	}
	if(isNull(average)){
		alert("请填写人均消费!");
		jQuery("#average").focus();
	    return false;	
	}
	if(!isValidNum(average)){
		alert("请填写正确的人均消费!");
		jQuery("#average").focus();
	    return false;
	}
	if(Length(average) > 6){
		alert("请不要恶意点评人均消费,人均消费在0-999999之间!");
		return false;
	}
	if(isNull(haveDinner)){
		 alert("请输入用餐目的!");
		 jQuery("#haveDinner").focus();
		 return false;
	}
	if(Length(commentDetail)<20){
	   alert("点评内容不能少于20个字!");
	   jQuery("#commentDetail").focus();
	   return false;
	}
	
	checkInput(commentDetail);
	commentDetail = commentDetail.replaceAll('\n','<br/>');
   jQuery.post('/comment_add.do', 
    {content:commentDetail,
    	service:gradeNum2,
    	environment:gradeNum3,
    	taste:gradeNum4,
    	objectType:7,
    	token:token,
    	haveDinner:haveDinner,
   		recommendFoo:recommendFoo,
   		discount:discount,
    	anonymous:anonymous,
    	average:average,
    	personRegionName:personRegionName,
    	objectUrl:objectURL,
    	objectId:companyId,
    	objectName:companyName},  
	    function (data){ //回传函数 
		 alert(data);
		//关闭窗口
		window.top.tb_remove();
		}); 
   //提交后清空添加点评的信息
// document.addFCommentForm.reset();
// jQuery("#contentCount").html('<tb class="asred" id="contentCount">0/5000</tb>');
// grade_clear(2,5);

//   if(location.href.indexOf('myshop')>0){
//		   jQuery("#foodv2_comment").html('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="/images/loading.gif" align="middle"/>');
//		   getFoodV2Comment(companyId,'1');//动态加载商家点评列表
//   }
}
	

	